package vj.array;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/*
 * Given two arrays A [n] and B[m], 
 * find the smallest window in A that contains all the elements of B.
 */

/*
 * Sample input
 * b = { 3, 7, 13, 6}
 * a = { 2, 3, 10, 4, 13, 6, 1, 3, 7, 5, 2 }
 */

public class SmallestWindow {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int a[] = new int[] { 2, 3, 10, 4, 13, 6, 1, 3, 7, 5, 2 };
		int b[] = new int[] { 3, 7, 13, 6};
		
					
	}
	
	public static int lenSmallestWindow(int a[], int b[]) {
		//Arrays.sort(b);
		int minLen = 0;
		boolean contains;
		for(int i = 0; i <= (a.length - b.length)  ; i++) {
			contains = true;
			int j;
			for(j = 0; j < b.length; j++) {
				if(find(a, i, a.length, b[j]) == -1) {
					contains = false;
					break;
				}
			}
			if(contains) {
				int len = j - i;
			}
		}
	}

	/*
	 * find the element k in array a[] between indices l and u not including u. ie [l, u)
	 */
	private static int find(int[] a, int l, int u, int k) {
		for(int i = l; i < u; i++) {
			if(a[i] == k)
				return i;
		}
		return -1;
	}

}
